const BaseController = {

    get: (request, response, handler) => {
        if (request.method !== "GET") {
            response.writeHead(405, {'Content-Type': 'application/json;charset=UTF-8'});
            response.end(JSON.stringify({code: 405, message: "Http 方法不支持"}))
            return;
        }
        response.writeHead(200, {'Content-Type': 'application/json;charset=UTF-8'});
        response.end(JSON.stringify({code: 200, message: "ok", data: handler()}));

    },


    post: (request, response, handler) => {
        if (request.method !== "POST") {
            response.writeHead(405, {'Content-Type': 'application/json;charset=UTF-8'});
            response.end(JSON.stringify({code: 405, message: "Http 方法不支持"}));
            return;
        }
        response.writeHead(200, {'Content-Type': 'application/json;charset=UTF-8'});
        response.end(JSON.stringify({code: 200, message: "ok", data: handler()}));

    }
}

module.exports = BaseController;
